package com.yepit.translate.controller;

import com.yepit.translate.dto.ImportInfo;
import com.yepit.translate.service.TranslateService;
import com.yepit.translate.util.excel.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author qianlong
 * @description //TODO
 * @Date 2019/4/20 9:36 AM
 **/
@RestController
public class TranslateController {

    @Autowired
    private TranslateService translateService;

//    /**
//     * 读取 Excel（允许多个 sheet）
//     */
//    @PostMapping(value = "traslateFile")
//    public Object readExcelWithSheets(MultipartFile excel) {
//        return ExcelUtils.readExcel(excel, new ImportInfo());
//    }

    /**
     * 读取 Excel（指定某个 sheet）
     */
    @PostMapping(value = "traslateFile")
    public void readExcel(@RequestParam("uploadFile") MultipartFile excel, int sheetNo,
                          @RequestParam(defaultValue = "1") int headLineNum, HttpServletResponse response) {
        try {
            translateService.translateFileViaExcel(excel, new ImportInfo(), sheetNo, headLineNum,
                    TranslateService.DEFAULT_API_TYPE, response);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}
